package sys.spvisor.core.service.project;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import sys.spvisor.core.dao.project.TFileFormMapper;
import sys.spvisor.core.entity.project.TFileForm;
import sys.spvisor.core.entity.project.TFileFormExample;
import sys.spvisor.core.entity.project.TFileFormExample.Criteria;

@Service
public class FileService {
	
	@Autowired
	TFileFormMapper tFileFormMapper;
	
	
	public List<TFileForm> selectByMsgIdAndType(int msgId, String type){
		TFileFormExample tFileFormExample = new TFileFormExample();
		Criteria criteria = tFileFormExample.createCriteria();
		criteria.andFileFormTypeEqualTo(type);
		criteria.andFileFormProjectIdEqualTo(msgId);
		return tFileFormMapper.selectByExample(tFileFormExample);
		
	}
	
	public List<TFileForm> selectByMsgIdAndTypeAndName(int msgId, String type,String name){
		TFileFormExample tFileFormExample = new TFileFormExample();
		Criteria criteria = tFileFormExample.createCriteria();
		criteria.andFileFormTypeEqualTo(type);
		criteria.andFileFormProjectIdEqualTo(msgId);
		criteria.andFileFormNameEqualTo(name);
		return tFileFormMapper.selectByExample(tFileFormExample);
		
	}
	
	public List<TFileForm> selectByTypeAndName(String type,String name){
		TFileFormExample tFileFormExample = new TFileFormExample();
		Criteria criteria = tFileFormExample.createCriteria();
		criteria.andFileFormTypeEqualTo(type);
		criteria.andFileFormNameEqualTo(name);
		return tFileFormMapper.selectByExample(tFileFormExample);
		 
	}
	
	public int deleteByTypeAndNameAndMsgId(int msgId, String type,String name){
		TFileFormExample tFileFormExample = new TFileFormExample();
		Criteria criteria = tFileFormExample.createCriteria();
		criteria.andFileFormTypeEqualTo(type);
		criteria.andFileFormNameEqualTo(name);
		criteria.andFileFormProjectIdEqualTo(msgId);
		return tFileFormMapper.deleteByExample(tFileFormExample);
	}

}
